package com.yanqu.road.server.cmd.activity.dafuweng;

import com.yanqu.road.entity.activity.dafuweng.DFWDollData;
import com.yanqu.road.pb.monopoly.MonopolyProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.dafuweng.DaFuWengMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_DA_FU_WENG_CHANGE_DOLL, desc = "更换人偶")
public class DaFuWengChangeDollCmd extends AbstractCommand {
    private int dollId;

    DFWDollData dollData = null;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        MonopolyProto.ChangeDollReqMsg msg = MonopolyProto.ChangeDollReqMsg.parseFrom(packet.getBytes());
        dollId = msg.getDollId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = DaFuWengMgr.checkGroup(player.getUserId());
        if (ret != 0) {
            return;
        }

        ret = DaFuWengMgr.changeDoll(player, dollId);
    }

    @Override
    public void sendData(GamePlayer player) {
        MonopolyProto.ChangeDollRespMsg.Builder respMsg = MonopolyProto.ChangeDollRespMsg.newBuilder();
        respMsg.setRet(ret);
        player.sendPacket(ClientProtocol.U_DA_FU_WENG_CHANGE_DOLL, respMsg);
    }
}
